﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using CE.iPhone.PList;
using cczEdit.DramaDialog;
namespace cczEdit.CommonInstructComposite
{
    public partial class UCCIGetItem : UserControl,ICommonInstruct
    {
        public UCCIGetItem()
        {
            InitializeComponent();
            foreach (Sundry sundry in UCDrama.sundries)
            {

                comboBoxName.Items.Add(sundry.name);
            }
            comboBoxName.SelectedIndex = 0;
        }

        public PListDict CreatResultDict()
        {
            Sundry sundry = UCDrama.sundries.Find(h => h.name == comboBoxName.Text);
            if (sundry == null)
            {
                MessageBox.Show("没有这个物品,请重试或尝试从下拉框选择");
                return null;
            }
            PListDict section = new PListDict();
            section.Add("Information", new PListString("获取"+sundry.name));
            PListArray conditions = new PListArray();
            PListDict posTestDict = AddDramaDialog.CreateConditionDict(kLogicalTestType.kLogicalTestTypeLocationOfCoord);
            posTestDict["CoordX"] = new PListInteger(Int32.Parse(textBoxX.Text));
            posTestDict["CoordY"] = new PListInteger(Int32.Parse(textBoxY.Text));
            posTestDict["UnitID"] = new PListInteger(514);
            conditions.Add(posTestDict);
            PListDict varTestDict = AddDramaDialog.CreateConditionDict(kLogicalTestType.kLogicalTestTypeVariable);
            varTestDict["TrueVariables"] = new PListArray();
            PListArray falseVars = new PListArray();
            falseVars.Add(new PListInteger((long)numericUpDownVar.Value));
            varTestDict["FalseVariables"] = falseVars;
            conditions.Add(varTestDict);
            section.Add("Condition", conditions);
            PListArray dramas = new PListArray();
            dramas.Add(UCDrama.GetInstructDict(kInstructType.kInstructTypeDramaBegin));
            PListDict getItemDict = AddDramaDialog.CreateInstructDict(kInstructType.kInstructTypeGetItem);

            getItemDict["ItemID"] = new PListInteger(sundry.num);
            getItemDict["ItemType"] = new PListInteger(0);
            getItemDict["UnitID"] = new PListInteger(516);
            dramas.Add(getItemDict);
            PListDict varSetDict = AddDramaDialog.CreateInstructDict(kInstructType.kInstructTypeVariableSet);
            varSetDict["VariableIndex"] = new PListInteger((long)numericUpDownVar.Value);
            varSetDict["Value"] = new PListBool(true);
            dramas.Add(varSetDict);
            dramas.Add(UCDrama.GetInstructDict(kInstructType.kInstructTypeDramaOver));
            section.Add("Dramas", dramas);
            return section;
        }
        
    }
}
